home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / graphics / flick_12.zip / CHUNKY8.S < prev    next >
Text File  |  1994-02-18  |  9KB  |  451 lines

  1. ;
  2. ;        Flick FLI-format Animation Viewer v1.2          19 Feb 1994
  3. ;        --------------------------------------
  4. ;
  5. ;
  6. ;This program plays FLI/FLC-format bitmapped animation files on any ECS
  7. ;or AGA Amiga running OS2.04 or higher.  FLI/FLC-format files are
  8. ;produced by Autodesk Animator and Autodesk 3D Studio on a PC, as well
  9. ;as by other programs.
  10. ;
  11. ;The files in this archive may be distributed anywhere provided they are
  12. ;unmodified and are not sold for profit.
  13. ;
  14. ;Ownership and copyright of all files remains with the author:
  15. ;
  16. ;    Peter McGavin, 86 Totara Crescent, Lower Hutt, New Zealand.
  17. ;    e-mail: peterm@maths.grace.cri.nz
  18. ;
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;        xdef    _chunky2planar
  21.  
  22. ; Basically the same as peterm/chunky6.s, except unwind loops
  23. ; as much as possible.  This is much better optimised for a 68040,
  24. ; but inefficient on lower processors.
  25.  
  26. ;-----------------------------------------------------------------------------
  27. ; Set Macro68 defaults
  28.  
  29.         default    _branch,_word
  30.         default    _adrbasedisp,_word
  31.         default    _pcbasedisp,_word
  32.         default    _outerdisp,_word
  33.         default    _absolute,_pcrel
  34.  
  35. ;-----------------------------------------------------------------------------
  36. ; chunky2planar:    (new Motorola syntax)
  37. ;  a0 -> chunky pixels
  38. ;  a1 -> plane0 (assume other 7 planes are allocated contiguously)
  39. ;  d1 = width*height/32 (if generic is defined)
  40.  
  41.  
  42.     ifnd generic
  43. plsiz        equ    width*height/8
  44.     endc
  45.  
  46.  
  47. _LVOCacheClearU equ    -636
  48.  
  49.     ifd generic
  50.     ifeq depth-8
  51. _c2p_8_040::
  52.     else
  53.     ifeq depth-6
  54. _c2p_6_040::
  55.     else
  56.     ifeq depth-4
  57. _c2p_4_040::
  58.     endc
  59.     endc
  60.     endc
  61.     else
  62.     ifeq depth-8
  63.         ifeq    width-320
  64. _c2p320x200x8_040::
  65.         endc
  66.     else
  67.     ifeq depth-6
  68.         ifeq    width-320
  69. _c2p320x200x6_040::
  70.         endc
  71.     else
  72.         die    "Unrecognised resolution"
  73.     endc
  74.     endc
  75.     endc
  76.  
  77.         movem.l    d2-d7/a2-a6,-(sp)
  78.  
  79.         bset    #0,(firsttimeflag)
  80.         bne.b    skip_relocate    ; branch if not being called 1st time
  81.  
  82. ; relocate the mainloop to a quad-longword boundary (for 030/040 cache line)
  83.  
  84.         lea    (begincode,pc),a2
  85.         adda.w    #15,a2
  86.         move.l    a2,d0
  87.         and.w    #~15,d0
  88.         movea.l    d0,a2
  89.         lea    (mainloop,pc),a3
  90.         move.w    #(endcode-mainloop)/2-1,d0
  91. 1$:        move.w    (a3)+,(a2)+
  92.         dbra    d0,1$
  93.  
  94. ; flush the caches
  95.  
  96.         movem.l    a0/a1/d1,-(sp)
  97.         movea.l    (4).w,a6
  98.         jsr    (_LVOCacheClearU,a6)
  99.         movem.l    (sp)+,a0/a1/d1
  100.  
  101. skip_relocate:    move.w    sp,d0
  102.         and.w    #15,d0
  103.         add.w    #64,d0        ; make room on stack for
  104.         suba.w    d0,sp        ; 64-byte quad-longword aligned buffer
  105.         movea.l    sp,a3        ; pointed to by a3
  106.         move.w    d0,-(sp)    ; and save the allocated size
  107.     ifd generic
  108.         move.l    d1,-(sp)    ; plsiz on stack at (6,sp)
  109.         move.l    d1,d0
  110.     ifgt depth-4
  111.         lsl.l    #3,d0
  112.     else
  113.         lsl.l    #2,d0
  114.     endc
  115.         sub.l    d1,d0
  116.         move.l    d0,-(sp)    ; 7*plsiz or 3*plsiz on stack at (2,sp)
  117.         lsr.l    #2,d1
  118.         subq.l    #1,d1
  119.         move.w    d1,-(sp)    ; outer loop counter on stack at (sp)
  120.     else
  121.         move.w    #plsiz/4-1,-(sp) ; outer loop counter on stack at (sp)
  122.     endc
  123.  
  124. ; set up register constants
  125.  
  126.         move.l    #$0f0f0f0f,d5    ; d5 = constant $0f0f0f0f
  127.         move.l    #$55555555,d6    ; d6 = constant $55555555
  128.         move.l    #$3333cccc,d7    ; d7 = constant $3333cccc
  129.  
  130. ; load up address registers with buffer ptrs
  131.  
  132.         lea    (4*4,a3),a4    ; a4 -> plane2buf
  133.     ifgt depth-4
  134.         lea    (4*4,a4),a5    ; a5 -> plane4buf
  135.         lea    (4*4,a5),a6    ; a6 -> plane6buf
  136.     endc
  137.  
  138. ; Macros part1 and part2 together convert 8 pixels from chunky to stack buffers
  139.  
  140. part1    macro
  141.         move.l    (a0)+,d2    ; 12 get next 4 chunky pixels in d2
  142.         move.l    (a0)+,d3    ; 12 get next 4 chunky pixels in d3
  143.  
  144.     ifgt depth-4
  145.         move.l    d2,d0        ;  4
  146.         and.l    d5,d2        ;  8 d5=$0f0f0f0f
  147.         move.l    d3,d1        ;  4
  148.         and.l    d5,d3        ;  8 d5=$0f0f0f0f
  149.         eor.l    d2,d0        ;  8
  150.         eor.l    d3,d1        ;  8
  151.         lsr.l    #4,d1        ; 16
  152.         or.l    d1,d0        ;  8
  153.     endc
  154.         lsl.l    #4,d2        ; 16
  155.         or.l    d3,d2        ;  8
  156.         move.l    d2,d3        ;  4
  157.         and.l    d7,d3        ;  8 d7=$3333cccc
  158.         eor.l    d3,d2        ;  8
  159.         lsr.w    #2,d3        ; 10
  160.         swap    d3        ;  4
  161.         lsl.w    #2,d3        ; 10
  162.         or.l    d2,d3        ;  8
  163.     ifgt depth-4
  164.         move.l    d0,d1        ;  4
  165.         and.l    d7,d1        ;  8 d7=$3333cccc
  166.         eor.l    d1,d0        ;  8
  167.         lsr.w    #2,d1        ; 10
  168.         swap    d1        ;  4
  169.         lsl.w    #2,d1        ; 10
  170.         or.l    d0,d1        ;  8
  171.         move.l    d1,d2        ;  4
  172.         lsr.l    #7,d2        ; 22
  173.         move.l    d1,d0        ;  4
  174.         and.l    d6,d0        ;  8 d6=$55555555
  175.     endc
  176.     endm
  177.  
  178. part2    macro
  179.     ifgt depth-4
  180.         eor.l    d0,d1        ;  8
  181.         move.l    d2,d4        ;  4
  182.         and.l    d6,d4        ;  8 d6=$55555555
  183.         eor.l    d4,d2        ;  8
  184.         or.l    d4,d1        ;  8
  185.         lsr.l    #1,d1        ; 10
  186.         move.b    d1,(8,a5)    ; 12 plane 5
  187.     ifgt depth-6
  188.         swap    d1        ;  4
  189.         move.b    d1,(8,a6)    ; 12 plane 7
  190.     endc
  191.         or.l    d0,d2        ;  8
  192.         move.b    d2,(a5)+    ;  8 plane 4
  193.     ifgt depth-6
  194.         swap    d2        ;  4
  195.         move.b    d2,(a6)+    ;  8 plane 6
  196.     endc
  197.     endc
  198.         move.l    d3,d2        ;  4
  199.         lsr.l    #7,d2        ; 22
  200.         move.l    d3,d0        ;  4
  201.         and.l    d6,d0        ;  8 d6=$55555555
  202.         eor.l    d0,d3        ;  8
  203.         move.l    d2,d4        ;  4
  204.         and.l    d6,d4        ;  8 d6=$55555555
  205.         eor.l    d4,d2        ;  8
  206.         or.l    d4,d3        ;  8
  207.         lsr.l    #1,d3        ; 10
  208.         move.b    d3,(8,a3)    ; 12 plane 1
  209.         swap    d3        ;  4
  210.         move.b    d3,(8,a4)    ; 12 plane 3
  211.         or.l    d0,d2        ;  8
  212.         move.b    d2,(a3)+    ;  8 plane 0
  213.         swap    d2        ;  4
  214.         move.b    d2,(a4)+    ;  8 plane 2
  215.     endm
  216.  
  217. ; optimised suba
  218.  
  219. subao    macro
  220.     ifd generic
  221.         suba.l    (6,sp),a1
  222.     else
  223.     iflt plsiz-32768
  224.         suba.w    #plsiz,a1
  225.     else
  226.         suba.l    #plsiz,a1
  227.     endc
  228.     endc
  229.     endm
  230.  
  231. ; convert the first 32 pixels to stack buffers as a special case
  232.  
  233.     rept    4
  234.         part1
  235.         part2
  236.     endr
  237.  
  238. begincode:    rept    8        ; space for mainloop code relocation
  239.         nop
  240.         endr
  241.  
  242. ; main loop (starts here) processes 64 chunky pixels at a time
  243.  
  244. mainloop:
  245.  
  246. ; Process the next 32 pixels from chunky to stack buffers while at the same
  247. ; time moving the result of the previous 32 pixels from stack buffers to
  248. ; Chip ram planes.
  249. ; Chip writes are spaced as widely apart as possible, so that there is
  250. ; always something useful happening while waiting for the Chip bus.
  251.  
  252.     ifgt depth-4
  253.     ifd generic
  254.         adda.l    (2,sp),a1        ; add 7*plsiz
  255.     else
  256.         adda.l    #7*plsiz,a1        ; a1 points into plane 0
  257.     endc
  258.     ifgt depth-6
  259.         move.l    (4,a6),(a1)        ; plane 7
  260.     endc
  261.         part1
  262.         subao
  263.     ifgt depth-6
  264.         move.l    (-4,a6),(a1)        ; plane 6
  265.     endc
  266.         part2
  267.         subao
  268.         move.l    (3,a5),(a1)        ; plane 5
  269.         part1
  270.         subao
  271.         move.l    (-5,a5),(a1)        ; plane 4
  272.         part2
  273.         subao
  274.         move.l    (2,a4),(a1)        ; plane 3
  275.         part1
  276.         subao
  277.         move.l    (-6,a4),(a1)        ; plane 2
  278.         part2
  279.         subao
  280.         move.l    (1,a3),(a1)        ; plane 1
  281.         part1
  282.         subao
  283.         move.l    (-7,a3),(a1)+        ; plane 0
  284.         part2
  285.     else
  286.     ifd generic
  287.         adda.l    (2,sp),a1        ; add 3*plsiz
  288.     else
  289.         adda.l    #3*plsiz,a1        ; a1 points into plane 0
  290.     endc
  291.         move.l    (4,a4),(a1)        ; plane 3
  292.         part1
  293.         part2
  294.         subao
  295.         move.l    (-5,a4),(a1)        ; plane 2
  296.         part1
  297.         part2
  298.         subao
  299.         move.l    (2,a3),(a1)        ; plane 1
  300.         part1
  301.         part2
  302.         subao
  303.         move.l    (-7,a3),(a1)+        ; plane 0
  304.         part1
  305.         part2
  306.     endc
  307.  
  308. ; check if finished
  309.  
  310.         sub.w    #1,(sp)
  311.         beq.w    done
  312.  
  313. ; restore stack buffer pointers
  314.  
  315.         subq.l    #8,a3
  316.         subq.l    #8,a4
  317.     ifgt depth-4
  318.         subq.l    #8,a5
  319.         subq.l    #8,a6
  320.     endc
  321.  
  322. ; Process the next 32 pixels from chunky to stack buffers while at the same
  323. ; time moving the result of the previous 32 pixels from stack buffers to
  324. ; Chip ram planes.
  325.  
  326.     ifgt depth-4
  327.     ifd generic
  328.         adda.l    (2,sp),a1        ; add 7*plsiz
  329.     else
  330.         adda.l    #7*plsiz,a1        ; a1 points into plane 0
  331.     endc
  332.     ifgt depth-6
  333.         move.l    (12,a6),(a1)        ; plane 7
  334.     endc
  335.         part1
  336.         subao
  337.     ifgt depth-6
  338.         move.l    (4,a6),(a1)        ; plane 6
  339.     endc
  340.         part2
  341.         subao
  342.         move.l    (11,a5),(a1)        ; plane 5
  343.         part1
  344.         subao
  345.         move.l    (3,a5),(a1)        ; plane 4
  346.         part2
  347.         subao
  348.         move.l    (10,a4),(a1)        ; plane 3
  349.         part1
  350.         subao
  351.         move.l    (2,a4),(a1)        ; plane 2
  352.         part2
  353.         subao
  354.         move.l    (9,a3),(a1)        ; plane 1
  355.         part1
  356.         subao
  357.         move.l    (1,a3),(a1)+        ; plane 0
  358.         part2
  359.     else
  360.     ifd generic
  361.         adda.l    (2,sp),a1        ; add 3*plsiz
  362.     else
  363.         adda.l    #3*plsiz,a1        ; a1 points into plane 0
  364.     endc
  365.         move.l    (12,a4),(a1)        ; plane 7
  366.         part1
  367.         part2
  368.         subao
  369.         move.l    (3,a4),(a1)        ; plane 5
  370.         part1
  371.         part2
  372.         subao
  373.         move.l    (10,a3),(a1)        ; plane 3
  374.         part1
  375.         part2
  376.         subao
  377.         move.l    (1,a3),(a1)+        ; plane 1
  378.         part1
  379.         part2
  380.     endc
  381.  
  382. ; check if finished, go back for more
  383.  
  384.         sub.w    #1,(sp)
  385.         bne.w    mainloop
  386.  
  387. ; correction
  388.  
  389.         addq.l    #4,a3
  390.         addq.l    #4,a4
  391.         addq.l    #4,a5
  392.         addq.l    #4,a6
  393.  
  394. ; write the last longword from stack buffer to planes
  395.  
  396. done:    ifd generic
  397.         adda.l    (2,sp),a1        ; add 7*plsiz or 3*plsiz
  398.     ifgt depth-4
  399.     ifgt depth-6
  400.         move.l    (4,a6),(a1)        ; plane 7
  401.     endc
  402.         subao
  403.     ifgt depth-6
  404.         move.l    (-4,a6),(a1)        ; plane 6
  405.     endc
  406.         subao
  407.     endc
  408.     else
  409.         adda.l    #(depth-1)*plsiz,a1    ; a1 points into plane 7
  410.     ifgt depth-6
  411.         move.l    (4,a6),(a1)        ; plane 7
  412.         subao
  413.         move.l    (-4,a6),(a1)        ; plane 6
  414.         subao
  415.     endc
  416.     endc
  417.     ifgt depth-4
  418.         move.l    (4,a5),(a1)        ; plane 5
  419.         subao
  420.         move.l    (-4,a5),(a1)        ; plane 4
  421.         subao
  422.     endc
  423.         move.l    (4,a4),(a1)        ; plane 3
  424.         subao
  425.         move.l    (-4,a4),(a1)        ; plane 2
  426.         subao
  427.         move.l    (4,a3),(a1)        ; plane 1
  428.         subao
  429.         move.l    (-4,a3),(a1)+        ; plane 0
  430.  
  431. ; all done!  restore stack and return
  432.  
  433.     ifd generic
  434.         adda.w    #4+4+2,sp        ; remove stack variables
  435.     else
  436.         addq.w    #2,sp            ; remove outer loop counter
  437.     endc
  438.         adda.w    (sp)+,sp        ; remove aligned 32-byte buffer
  439.         movem.l    (sp)+,d2-d7/a2-a6
  440.  
  441.         rts
  442.  
  443. endcode:
  444.  
  445. firsttimeflag:    dc.b    0
  446.         even
  447.  
  448. ;-----------------------------------------------------------------------------
  449.  
  450.         end
  451.